/*
 * =============================================================================
 * Copyright by Benjamin Sempere,
 * All rights reserved.
 * =============================================================================
 * Author  : Benjamin Sempere
 * E-mail  : benjamin@sempere.org
 * Homepage: www.sempere.org
 * =============================================================================
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.sempere.commons.logging.log4j;

import org.apache.log4j.Level;
import org.sempere.commons.logging.Logger;

/**
 * Logger implementation based on Log4J API.
 * 
 * @author bsempere
 */
public class Log4JLogger extends org.apache.log4j.Logger implements Logger {

	private static final String CLASSNAME = Log4JLogger.class.getName() + ".";

	/**
	 * Default class constructor
	 * 
	 * @param name
	 */
	protected Log4JLogger(String name) {
		super(name);
	}

	/**
	 * Get a Log4JLogger on a specific class
	 * 
	 * @param clazz
	 * @return Logger
	 */
	public static Log4JLogger getLogger(Class<?> clazz) {
		return getLogger(clazz.getName());
	}

	/**
	 * Get a Log4JLogger on the given class name
	 * 
	 * @param className
	 * @return Logger
	 */
	public static Log4JLogger getLogger(String className) {
		return (Log4JLogger) org.apache.log4j.Logger.getLogger(className, Log4JLoggerFactory.getInstance());
	}

	// ********************************************************************************
	//
	// Logger methods implementation
	//
	// ********************************************************************************

	public boolean isWarnEnabled() {
		return super.isEnabledFor(Level.WARN);
	}

	public boolean isErrorEnabled() {
		return super.isEnabledFor(Level.ERROR);
	}

	public void debug(String message) {
		super.log(CLASSNAME, Level.DEBUG, message, null);
	}

	public void debug(String message, Throwable throwable) {
		super.log(CLASSNAME, Level.DEBUG, message, null);
	}

	public void info(String message) {
		super.log(CLASSNAME, Level.INFO, message, null);
	}

	public void info(String message, Throwable throwable) {
		super.log(CLASSNAME, Level.INFO, message, throwable);
	}

	public void warn(String message) {
		super.log(CLASSNAME, Level.WARN, message, null);
	}

	public void warn(String message, Throwable throwable) {
		super.log(CLASSNAME, Level.WARN, message, throwable);
	}

	public void error(String message) {
		super.log(CLASSNAME, Level.ERROR, message, null);
	}

	public void error(String message, Throwable throwable) {
		super.log(CLASSNAME, Level.ERROR, message, throwable);
	}
}
